package com.panda.order.controller;

import com.panda.common.annotation.Log;
import com.panda.common.core.controller.BaseController;
import com.panda.common.core.domain.AjaxResult;
import com.panda.common.core.page.TableDataInfo;
import com.panda.common.enums.BusinessType;
import com.panda.common.utils.poi.ExcelUtil;
import com.panda.order.domain.TPandaOrderHead;
import com.panda.order.service.ITPandaOrderHeadService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.Calendar;
import java.util.List;

/**
 * 淘宝订单信息Controller
 * 
 * @author panda
 * @date 2021-03-14
 */
@RestController
@RequestMapping("/order/orderHead")
public class TPandaOrderHeadController extends BaseController
{
    @Autowired
    private ITPandaOrderHeadService tPandaOrderHeadService;

    /**
     * 查询淘宝订单信息列表
     */
    @PreAuthorize("@ss.hasPermi('order:orderHead:list')")
    @GetMapping("/list")
    public TableDataInfo list(TPandaOrderHead tPandaOrderHead)
    {
        startPage();
        if(tPandaOrderHead !=null &&tPandaOrderHead.getEnd() != null){
            Calendar calendar = Calendar.getInstance();
            calendar.setTime(tPandaOrderHead.getEnd());
            calendar.add(Calendar.DATE, 1);
            tPandaOrderHead.setEnd(calendar.getTime());
        }
        List<TPandaOrderHead> list = tPandaOrderHeadService.selectTPandaOrderHeadList(tPandaOrderHead);
        return getDataTable(list);
    }

    /**
     * 导出淘宝订单信息列表
     */
    @PreAuthorize("@ss.hasPermi('order:orderHead:export')")
    @Log(title = "淘宝订单信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TPandaOrderHead tPandaOrderHead)
    {
        List<TPandaOrderHead> list = tPandaOrderHeadService.selectTPandaOrderHeadList(tPandaOrderHead);
        ExcelUtil<TPandaOrderHead> util = new ExcelUtil<TPandaOrderHead>(TPandaOrderHead.class);
        return util.exportExcel(list, "orderHead");
    }

    /**
     * 获取淘宝订单信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('order:orderHead:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(tPandaOrderHeadService.selectTPandaOrderHeadById(id));
    }

    /**
     * 新增淘宝订单信息
     */
    @PreAuthorize("@ss.hasPermi('order:orderHead:add')")
    @Log(title = "淘宝订单信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TPandaOrderHead tPandaOrderHead)
    {
        return toAjax(tPandaOrderHeadService.insertTPandaOrderHead(tPandaOrderHead));
    }

    /**
     * 修改淘宝订单信息
     */
    @PreAuthorize("@ss.hasPermi('order:orderHead:edit')")
    @Log(title = "淘宝订单信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TPandaOrderHead tPandaOrderHead)
    {
        return toAjax(tPandaOrderHeadService.updateTPandaOrderHead(tPandaOrderHead));
    }

    /**
     * 删除淘宝订单信息
     */
    @PreAuthorize("@ss.hasPermi('order:orderHead:remove')")
    @Log(title = "淘宝订单信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tPandaOrderHeadService.deleteTPandaOrderHeadByIds(ids));
    }
}
